package com.oa.wk.action;

import java.util.List;

import org.apache.struts2.ServletActionContext;

import com.oa.domain.Emp;
import com.oa.wk.service.EmpService;
import com.opensymphony.xwork2.ActionSupport;

public class EmpAction extends ActionSupport {

	private EmpService empService;

	public void setEmpService(EmpService empService) {
		this.empService = empService;
	}
	
	/**
	 * 锟斤拷询员锟斤拷锟斤拷锟斤拷锟斤拷息
	 * */

	private List<Emp> emps;

	public List<Emp> getEmps() {
		return emps;
	}
	
	public String execute() throws Exception {
		emps = empService.getEmp();
		return SUCCESS;
	}
	
	
	
	
	private Emp emp;

	public Emp getEmp() {
		return emp;
	}

	public void setEmp(Emp emp) {
		this.emp = emp;
	}

	/**
	 * 锟斤拷锟皆憋拷锟斤拷锟较�
	 * */
	public String addEmp() throws Exception {
		
		System.out.println(""+emp.getSex());
		empService.addEmp(emp);
		return SUCCESS;
	}


	public String getInfo(){
		System.out.println(ServletActionContext.getRequest().getParameter("empno"));
		List<Emp> list = (List<Emp>) empService.getEmpByEmpno(Integer.parseInt(ServletActionContext.getRequest().getParameter("empno")));
		System.out.println("list:"+list.size());
		ServletActionContext.getRequest().setAttribute("list", list);
		return "GOUPD";
	}

	//�޸�Ա����Ϣ
	public String updInfo(){
	
		empService.updateEmpByEmpno(emp);
	
		return SUCCESS;
	}
	
	public String delInfo(){
		Emp emp = new Emp();
		emp.setEmpno(Long.parseLong(ServletActionContext.getRequest().getParameter("empno")));
		empService.deleteEmpByEmpno(emp);
		return SUCCESS;
	}
}